package gcd;

/**
 * Finds Greatest Common Divisor using brute force search
 * @author NP
 *
 */
public class BruteGCD {

	public static int find(int a, int b) {
		if ((a == 0)||(b == 0)) return -1;
		if (a == b) return a;
		if (a < b) {
			int t = b;
			b = a;
			a = t;
		}
		if (a % b == 0) return b;
		for (int i = b/2; i > 1; i--) {
			if ((a % i == 0)&&(b % i ==0)) return i;
		}
		return 1;
	}

}
